SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO










alter view v_tt_billinit  
as 
  SELECT tb.tid AS tid, tb.bid,bstate, tb.bdate, tb.btype, tb.ioflag,tb.bprice, 
    tb.bcode AS bcode, tb.bno AS bno, tb.depotid, tb.productid, tb.bquantity AS bquantity,
    case when tb.bquantity <> 0 then tb.amount / tb.bquantity else tb.price end AS b_price ,tb.amount as amount,
    tb.assqty AS assqty, tb.unitid AS unitid, tb.unitrate AS unitrate, td.name as depotname, tb.price price,tb.quantity quantity,
    tp.calccost,
    dbo.f_getunitqty(productid, tb.bquantity, 1) AS qty1,  
    dbo.f_getunitqty(productid, tb.bquantity, 2) AS qty2,  
    dbo.f_getunitqty(productid, tb.bquantity, 3) AS qty3,
    tb.custom1,tb.custom2,tb.custom3
    FROM tt_bill tb 
    left join td_depot td on tb.depotid = td.depotid
    left join td_product tp on tb.productid=tp.p_id
    where btype < 0








GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



